import React, {useEffect} from 'react';
import {StyleSheet, View} from 'react-native';
import {ScreensParamList} from 'types';
import {StackNavigationProp} from '@react-navigation/stack';
import {useDispatch} from 'react-redux';
import actions from 'reduxState/actions';
import {VirgetParamType} from 'components/VirScroll';
import {ResponseType} from 'utils/request';
import EventList from 'pages/EventListScreen/EventList';
import api from 'service';

type WebScreenNavigationProp = StackNavigationProp<ScreensParamList>;

export interface Props {
  navigation: WebScreenNavigationProp;
}
const limit = 10;
function Comments({navigation}: Props) {
  const dispatch = useDispatch();

  const getData = async function getData({offset}: VirgetParamType) {
    const {data}: ResponseType = await api.getUserGoing(offset, limit);
    return {list: data.events, hasMore: data.hasMore};
  };
  useEffect(() => {
    const unsubscribe = navigation.addListener('tabPress', (e) => {
      // 设置detailsTab激活
      dispatch(actions.setActiveTab('Going'));
    });

    return unsubscribe;
  }, [dispatch, navigation]);
  return (
    <>
      <View style={styles.container}>
        <EventList queryFn={getData} />
      </View>
    </>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingHorizontal: 20,
    backgroundColor: '#FAF9FC',
  },
  line: {
    marginTop: 24,
    marginBottom: 16,
  },
});
export default Comments;
